package com.lanyou.cook.repository;

import java.util.List;

import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.Repository;
import org.springframework.data.rest.core.annotation.RestResource;

import com.lanyou.cook.entity.domain.DBlink;

public interface DBlinkRepository extends Repository<DBlink, String>, JpaSpecificationExecutor<DBlink> {

	@RestResource(exported = false)
	DBlink findByname (String name);
	
	@RestResource(exported = false)
	Long countByFieldSystem_Id(String fieldSystemId);
	 
	@RestResource(exported = false)
	DBlink findByNameAndOwnerHost(String name,String ownerHost);
	
	@RestResource(exported = false)
	List<DBlink> findByNameAndHost(String name,String host);
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"dbLinkManagement:maintain"})
	<S extends DBlink> S save(S entity);	// could expose REST API
	
	<S extends DBlink> List<S> save(Iterable<S> entities);
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"dbLinkManagement:maintain","dbLinkManagement:view"},logical=Logical.OR)
	DBlink findOne(String id);	// could expose REST API
	
	DBlink getOne(String id);
	
	// 以下三个接口只能选一个暴露为REST API
	
	@RestResource(exported = false)
	List<DBlink> findAll();	// could expose REST API
	
	@RestResource(exported = false)
	List<DBlink> findAll(Sort sort);	// could expose REST API
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"dbLinkManagement:maintain","dbLinkManagement:view"},logical=Logical.OR)
	Page<DBlink> findAll(Pageable pageable);	// could expose REST API
	
	List<DBlink> findAll(Iterable<String> ids);
	
	// 以下两个接口，要么都暴露为REST API，要么都不暴露
	@RestResource(exported = true)
	@RequiresPermissions(value={"dbLinkManagement:maintain"})
	void delete(String id);	// could expose REST API
	
	@RestResource(exported = true)
	@RequiresPermissions(value={"dbLinkManagement:maintain"})
	void delete(DBlink entity);	// could expose REST API
	
	void delete(Iterable<? extends DBlink> entities);
	
	void deleteAll();
	
	void flush();
	
	<S extends DBlink> S saveAndFlush(S entity);
	
	void deleteInBatch(Iterable<DBlink> entities);
	
	void deleteAllInBatch();
	
}